<%--
  Created by IntelliJ IDEA.
  User: huasheng
  Date: 2023/11/24
  Time: 17:06
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<!-- 新增和修改对话框 -->
<div class="modal fade" id="modal_dept_edit" role="dialog" aria-labelledby="modal_dept_edit" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <form id="form_dept" method="post" action="saveStu">
                    <table style="border-collapse:separate; border-spacing:0px 10px;">
                        <tr>
                            <td>姓名：</td>
                            <td><input type="text" id="name" name="name"
                                       class="form-control" aria-required="true" required/>
                                <span style="color: red;" id="s"></span></td>
                        </tr>
                        <tr>
                            <td>年龄：</td>
                            <td><input type="text" id="age" name="age"
                                       class="form-control" aria-required="true" required/></td>
                        </tr>
                        <tr>
                            <td>性别：</td>
                            <td><input type="radio" id="s1" name="sex" value="男"/>男
                                <input type="radio" id="s2" name="sex" value="女"/>女</td>
                        </tr>

                        <tr>
                            <td>爱好：</td>
                            <td><input type="checkbox" id="a" name="hobby" value="看书"/>看书
                                <input type="checkbox" id="b" name="hobby" value="旅游"/>旅游
                                <input type="checkbox" id="c" name="hobby" value="篮球"/>篮球
                            </td>
                        </tr>

                        <tr>
                            <td>专业：</td>
                            <td> <select name="mid">
                                <option value="">--请选择--</option>
                                <c:forEach items="${majorList}" var="m">
                                    <option value="${m.id}">${m.mname}</option>
                                </c:forEach>
                            </select>
                            </td>
                        </tr>

                        <tr>
                            <td>老师：</td>
                            <td> <select name="tid">
                                <option value="">--请选择--</option>
                                <c:forEach items="${teacherList}" var="t">
                                    <option value="${t.id}">${t.tname}</option>
                                </c:forEach>
                            </select>
                            </td>
                        </tr>

                        <tr>
                            <td> 生日：</td>
                            <td><input type="date" name="birthday"></td>
                        </tr>

                    </table>

                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary" id="submit_form_dept_btn">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    </div>
                </form>

            </div>

        </div>

    </div>

</div>
<script src="${pageContext.request.contextPath}/resources/js/jquery-1.8.3.js"></script>
<!-- 
<script>
    var a = false;
    $("#name").blur(function () {
        var name = $("#name").val();
        $.post("findByName",{"name":name},function (data){
            if(data=="ok"){
                $("#s").html("√√√√√√√√√√");
                a=true;
            }else {
                $("#s").html("XXXXXXXXX");
                a=false;
            }
        })
    });
    $("#form_dept").submit(function () {
        return a;
    });
</script>


    @Override
    public void outFilm( HttpServletResponse response ) throws IOException {
        //1.创建表格
        XSSFWorkbook workbook = new XSSFWorkbook();

        //2.创建sheet页
        XSSFSheet sheet = workbook.createSheet();

        //3.创建行
        String[] titles = {"编号", "电影", "电影类别", "票价", "状态", "上映时间", "制片厂"};
        XSSFRow oneRow = sheet.createRow(0);
        for (int i = 0; i < titles.length; i++) {
            oneRow.createCell(i).setCellValue(titles[i]);
        }

        //4.查询数据
        List<FilmVo> list = filmMapper.findOut();

        //5.循环遍历集合,把数据依次放到表格行里面
        int index = 1;
        for (FilmVo vo : list) {
            XSSFRow row = sheet.createRow(index);
            row.createCell(0).setCellValue(vo.getId());
            row.createCell(1).setCellValue(vo.getName());
            row.createCell(2).setCellValue(vo.getTname());
            row.createCell(3).setCellValue(vo.getPrice());
            if (vo.getStatus().equals("0")) row.createCell(4).setCellValue("待映");
            if (vo.getStatus().equals("1")) row.createCell(4).setCellValue("在映");
            if (vo.getStatus().equals("2")) row.createCell(4).setCellValue("下播");
            row.createCell(5).setCellValue(new SimpleDateFormat("yyyy-MM-dd").format(vo.getCreatetime()));
            row.createCell(6).setCellValue(vo.getPname());
            index++;
        }
        //6.下载到桌面
        ImgUtil.download(response, "考试.xlxs", workbook);
    }


    @Override
    public void importFilm( InputStream inputStream, String username ) throws IOException {
        //1.创建excel表格
        XSSFWorkbook workbook = new XSSFWorkbook(inputStream);

        //2.获取sheet
        XSSFSheet sheetAt = workbook.getSheetAt(0);

        //3.获取最大行数
        int num = sheetAt.getPhysicalNumberOfRows();

        //4.for循环遍历
        for (int i = 1; i < num; i++) {
            XSSFRow row = sheetAt.getRow(i);
            Film film = new Film();
            film.setName(row.getCell(0).getStringCellValue());
            film.setPrice((int) row.getCell(1).getNumericCellValue());
            film.setCreatetime(row.getCell(3).getDateCellValue());
            String status = row.getCell(4).getStringCellValue();
            if (status.equals("待映")) film.setStatus("0");
            if (status.equals("在映")) film.setStatus("1");
            if (status.equals("下播")) film.setStatus("2");
            String tname = row.getCell(2).getStringCellValue();
            String pname = row.getCell(5).getStringCellValue();
            Gtype gtype = gtypeMapper.findByName(tname);
            Producer producer = producerMapper.findByName(pname);
            film.setTid(gtype.getId());
            film.setPid(producer.getId());
            film.setLoginname(username);
            film.setJoindate(new Date());
            film.setIsdelete("1");
            filmMapper.insertSelective(film);//执行添加
        }
-->
    }
	
</body>
</html>
